<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/14/014
 * Time: 15:49
 */

namespace App\Http\Controllers\Demo;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\Count\CountService;
use App\Http\Controllers\Controller;
//use Illuminate\Support\Facades\Redis;
use Session,Config;
use Cache;

class CountController extends Controller
{
    /**
     * @return view
     * Demo页面
     */
    public function index()
    {
        return view('Demo.count');
    }

    /**
     * @param Request $request
     * 用户账号列表
     */
    public function getApiCountList(Request $request)
    {

        $where = $request->except('_token');

        if ($request->has('page')) {
            $where['page_no'] = $request->input('page');
            unset($where['page']);
        }
        if ($request->has('limit')) {
            $where['page_size'] = $request->input('limit');
            unset($where['limit']);
        } else {
            $where['page_size'] = 20;
        }


        foreach ($where as $key => $value) {
            if ($value == '' || $value == 'undefined') {
                unset($where[$key]);
            }
        }

        $user = new CountService();
        $data = $user->getApiCountList($where);

        if($data){
            foreach ($data['data']['data'] as &$v) {
                if ($v['daily_limit_type'] == 1) {
                    $v['daily_limit_type_name'] = '不限量';
                } else {
                    $v['daily_limit_type_name'] = '限量';
                }
            }
        }

        return json_encode($data);

    }

}